//
//  MessageDetailsViewController.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/9/24.
//

#import "MessageDetailsViewController.h"
#import "MessageModel.h"

@interface MessageDetailsViewController ()
@property (nonatomic ,strong) MessageModel * model;
@property (nonatomic ,strong) UIScrollView * scrollView;
@end

@implementation MessageDetailsViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self refreshingData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIView * topview = [UIView new];
    topview.backgroundColor = KcolorHex(@"#0967FF");
    [self.view addSubview:topview];
    [topview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.offset(0);
        make.height.offset(Knav_HeightX);
    }];
    MJWeakSelf
    UIView * backview = [UIView new].addClickBlock(^{
        [weakSelf back];
    });
    [topview addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(44);
        make.left.bottom.offset(0);
        make.width.offset(kwt(140));
    }];
    
    UIImageView * leftimg = kimageView(@"white_path");
    [backview addSubview:leftimg];
    [leftimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(20);
        make.left.offset(kwt(10));
        make.centerY.offset(0);
    }];
    
    UILabel * leftlab = [DTKTool labelWithText:@"详情" andFont:kCFont(19) andTextColor:UIColor.whiteColor];
    [backview addSubview:leftlab];
    [leftlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.offset(kwt(45));
    }];
    
    UIScrollView * scrollView = [UIScrollView new];
    self.scrollView = scrollView;
    [self.view addSubview:scrollView];
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.view);
        make.top.equalTo(topview.mas_bottom);
    }];
    [self YDApi];
}
- (void)YDApi{
    [self.view showBusyHUD];
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    [dict setObject:self.ID forKey:@"id"];
    [SCNetManger PostsysSmsAppIsReadWithDict:dict  andCompetionHandlerBlock:^(HTTPArrBase * model) {
        [self.view hideBusyHUD];
        if(model.code ==200){
        } else {
            [self.view showWarning:model.message];
        }
    }];
    
}

- (void)loadNewData{
    [self.view showBusyHUD];
    
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    [dict setObject:self.ID forKey:@"id"];
    [SCNetManger PostsysSmsAppQueryByIdWithDict: dict andCompetionHandlerBlock:^(HTTPDicBase * model) {
        [self.view hideBusyHUD];
        if(model.code ==200){
            self.model = [MessageModel yy_modelWithDictionary:model.result];
            
        } else {
            [self.view showWarning:model.message];
        }
    }];
}
- (void)setModel:(MessageModel *)model{
    _model = model;
    
    UIView *contentView = [[UIView alloc] init];
    [self.scrollView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.scrollView);
        make.width.offset(SCREEN_WIDTH);
    }];
    
    UILabel * title = [DTKTool labelWithText:model.title andFont:kCFont(18) andTextColor:KcolorHex(@"#222222")];
    title.numberOfLines = 0;
    [contentView addSubview:title];
    [title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(24));
        make.left.offset(kwt(15));
        make.right.offset(kwt(-15));
    }];
    UILabel * createTime = [DTKTool labelWithText:model.createTime andFont:kFont(15) andTextColor:KcolorHex(@"#7D7D7D")];
    [contentView addSubview:createTime];
    [createTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(title.mas_bottom).offset(kwt(10));
        make.left.offset(kwt(15));
        make.right.offset(kwt(-15));
    }];
    
    UILabel * content = [DTKTool labelWithText:model.content andFont:kFont(17) andTextColor:KcolorHex(@"#222222")];
    content.attributedText = [DTKTool AttributedStringWithStr:model.content andNodeColor:KcolorHex(@"#222222") andSeledColor:KcolorHex(@"#222222") andFont:kFont(17) andPattenr:@""];
    content.numberOfLines = 0;
    [contentView addSubview:content];
    [content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(createTime.mas_bottom).offset(kwt(24));
        make.left.offset(kwt(15));
        make.right.offset(kwt(-15));
        make.bottom.equalTo(contentView.mas_bottom).offset(kwt(-20));
    }];
    
    //    self.scrollView
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
